package com.omybug.study.service;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author: omybug
 * @date: 18/9/24 19:52
 */
@Aspect
public class LogService {

    @Pointcut("execution(public String com.omybug.study.controller.Game.*())")
    public void pointCut(){

    }

    @Around("pointCut()")
    public void around(ProceedingJoinPoint joinPoint){
        try {
            System.out.println("around 1.");
//            joinPoint.proceed();
            System.out.println("around 2.");
        }catch (Throwable e){
            System.out.println("throwable");
        }

    }

//    @Before("public String com.omybug.study.controller.Game.pay()")
    @Before("pointCut()")
    public void logStart(JoinPoint joinPoint){
        System.out.println("start..." + joinPoint.getSignature().getName());
    }

    @After("com.omybug.study.service.LogService.pointCut()")
    public void logEnd(){
        System.out.println("end...");
    }

    // JoinPoint必须放在参数第一位
    @AfterReturning(value = "pointCut()", returning = "obj")
    public void logReturn(JoinPoint joinPoint, Object obj){
        System.out.println("return..." + obj.toString());
    }

    @AfterThrowing(value = "pointCut()", throwing = "exp")
    public void logException(JoinPoint joinPoint, Exception exp){
        System.out.println("exception..." + exp.toString());
    }
}
